﻿using System;
using System.IO;
using System.Text.RegularExpressions;

namespace Brianhdk.Utils.VisualStudio.AssemblyInfoDialog
{
    internal static class AssemblyFilePathStrategy
    {
        public static IAssemblyFilePathStrategy Create(string itemPath)
        {
            string extension = Path.GetExtension(itemPath);

            if (!String.IsNullOrEmpty(extension))
            {
                if (Regex.IsMatch(extension, @"\.(?:cs|fs|vb)proj", RegexOptions.IgnoreCase))
                    return new RetrieveAssemblyFilePathFromProjectFile(itemPath);

                if (Regex.IsMatch(extension, @"\.(?:exe|dll)", RegexOptions.IgnoreCase))
                    return new ReturnAssemblyFilePathDirectly(itemPath);
            }

            throw new MissingAssemblyFilePathStrategyException(itemPath);
        }
    }
}